﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using System.Diagnostics;
using Common;

namespace SmartLauncher
{
    public partial class LauncherForm : Form
    {
        bool IsLoginScreen()
        {
            NativeApi.EnumWindowsCB cb = new NativeApi.EnumWindowsCB(FindLoginWindowCB);
            NativeApi.EnumWindows(cb, 0);
            return loginWindow != null;
        }
        bool IsLobbyScreen()
        {
            NativeApi.EnumWindowsCB cb = new NativeApi.EnumWindowsCB(FindLobbyWindowCB);
            NativeApi.EnumWindows(cb, 0);
            return lobbyWindow != null;
        }
        bool IsMyNewsScreen()
        {
            NativeApi.EnumWindowsCB cb = new NativeApi.EnumWindowsCB(FindMyNewsWindowCB);
            NativeApi.EnumWindows(cb, 0);
            return myNewsWindow != null;
        }
        bool IsRegisterScreen()
        {
            registerWindow = null;
            NativeApi.EnumWindowsCB cb = new NativeApi.EnumWindowsCB(FindRegisterWindowCB);
            NativeApi.EnumWindows(cb, 0);
            return registerWindow != null;
        }
        bool IsRegisteredScreen()
        {
            registeredWindow = null;
            NativeApi.EnumWindowsCB cb = new NativeApi.EnumWindowsCB(FindRegisteredWindowCB);
            NativeApi.EnumWindows(cb, 0);
            return registeredWindow != null;
        }
        bool IstBuyInScreen()
        {
            _buyInWindow = null;
            NativeApi.EnumWindowsCB cb = new NativeApi.EnumWindowsCB(FindBuyInWindowCB);
            NativeApi.EnumWindows(cb, 0);
            return _buyInWindow != null;
        }
        bool FindRegisterWindowCB(IntPtr hwnd, int lparam)
        {
            AppWindow win = new AppWindow(hwnd);
            if (win.Title.Contains("Tournament") && win.Title.Contains("Lobby"))
            {
                registerWindow = win;
                return false;
            }
            return true;
        }
        bool FindRegisteredWindowCB(IntPtr hwnd, int lparam)
        {
            AppWindow win = new AppWindow(hwnd);
            if (win.Title.Contains("Tournament") && win.Title.Contains("Registration"))
            {
                registeredWindow = win;
                return false;
            }
            return true;
        }

        bool FindBuyInWindowCB(IntPtr hwnd, int lparam)
        {
            AppWindow win = new AppWindow(hwnd);
            if (win.Title.Contains("Tournament Registration"))
            {
                _buyInWindow = win;
                return false;
            }
            return true;
        }
        bool IsResultWindowDisplayed()
        {
            resultWindow = null;
            NativeApi.EnumWindowsCB cb = new NativeApi.EnumWindowsCB(FindResultWindowCB);
            NativeApi.EnumWindows(cb, 0);
            return resultWindow != null;
        }
        bool FindResultWindowCB(IntPtr hwnd, int lparam)
        {
            AppWindow win = new AppWindow(hwnd);
            if (win.Title == "PokerStars")
            {
                resultWindow = win;
                return false;
            }
            return true;
        }
        bool IsTableScreen()
        {
            tableWindow = null;
            NativeApi.EnumWindowsCB cb = new NativeApi.EnumWindowsCB(FindTableWindowCB);
            NativeApi.EnumWindows(cb, 0);
            return tableWindow != null;
        }
        bool FindTableWindowCB(IntPtr hwnd, int lparam)
        {
            if(tableWorkerDic.ContainsKey(hwnd))
            {
                return true;
            }
            AppWindow win = new AppWindow(hwnd);
            if (win.Title.Contains("Table") && win.Title.Contains("Tournament"))
            {
                tableWindow = win;
                return false;
            }
            return true;
        }
        bool FindLobbyWindowCB(IntPtr hwnd, int lparam)
        {
            AppWindow win = new AppWindow(hwnd);
            if (win.Title.Contains("PokerStars Lobby"))
            {
                lobbyWindow = win;
                return false;
            }
            return true;
        }
        bool FindMyNewsWindowCB(IntPtr hwnd, int lparam)
        {
            AppWindow win = new AppWindow(hwnd);
            if (win.Title.Contains("News"))
            {
                myNewsWindow = win;
                return false;
            }
            return true;
        }
        bool FindLoginWindowCB(IntPtr hwnd, int lparam)
        {
            AppWindow win = new AppWindow(hwnd);
            if (win.Title.Contains("Log In"))
            {
                loginWindow = win;
                return false;
            }
            return true;
        }
    }
}
